package com.neuedu.yyzx.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.neuedu.yyzx.common.CommonResult;
import com.neuedu.yyzx.entity.CarePurchased;
import com.neuedu.yyzx.service.ICarePurchasedService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 已购护理服务  前端控制器
 * </p>
 *
 * @author dya
 * @since 2021-04-27
 */
@RestController
@RequestMapping("//carePurchased")
public class CarePurchasedController {

    @Autowired
    ICarePurchasedService carePurchasedService;

    @RequestMapping("/list")
    CommonResult list(Page page, CarePurchased carePurchased){
        QueryWrapper queryWrapper = new QueryWrapper();
        if (carePurchased!=null && StringUtils.isNotEmpty(carePurchased.getCustomerName())){
            queryWrapper.like("customer_name",carePurchased.getCustomerName());
        }
        return CommonResult.success(carePurchasedService.page(page,queryWrapper));
    }

    @RequestMapping("/add")
    CommonResult add(CarePurchased carePurchased){
        return CommonResult.success(carePurchasedService.saveOrUpdate(carePurchased));
    }

    @RequestMapping("/update")
    CommonResult update(CarePurchased carePurchased){
        return CommonResult.success(carePurchasedService.updateAll(carePurchased));
    }

    @RequestMapping("/getById")
    CommonResult getById(Integer careId){
        return CommonResult.success(carePurchasedService.getById(careId));
    }
}
